<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
   <script type="text/javascript">
   		var nodecheck=false;
		var store = new Ext.data.JsonStore({
			root: "data",//从返回的json对象data中读取数据
			fields: ["rid", "rname","did", "dname", "oid", "oname","remark"],
  			url:"role!listByDepID.action"
    	});
    	//获取部门信息
		var store2 = new Ext.data.JsonStore({
			root: "data",//从返回的json对象data中读取数据
			fields: ["id","name"],
  			url:"depart!listByOrg.action"
    	});
    	//获取机构信息
		var store3 = new Ext.data.JsonStore({
			root: "data",//从返回的json对象data中读取数据
			fields: ["rid", "rname","did", "dname", "oid", "oname","remark"],
  			url:"role!listByDepID.action"
    	});    	
    	    	
		var p1 = {
			id: "rolegrid",
			xtype: "grid",
			stripeRows:true,
			loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
			autoExpandColumn:"remark",//自动填充
			autoExpandMin : 100,//自动填充最小宽度
			store:store,
			headersDisabled: true,
			columns:[
	        	new Ext.grid.RowNumberer({header: "序号", width: 35}),
	        	{header: "角色编号", dataIndex: "rid",	menuDisabled: true},
	        	{header: "角色名称", dataIndex: "rname",	menuDisabled: true},
	        	{header: "部门名称", dataIndex: "dname",	menuDisabled: true},
				{header: "机构名称", dataIndex: "oname",	menuDisabled: true},
				{header: "备注",dataIndex:"remark",id:"remark",menuDisabled: true}
			],
        	buttonAlign:"center",
			buttons:[
				{text:"查看详情", handler: function(){
				var record=Ext.getCmp("rolegrid").getSelectionModel().getSelected();//获取列表中被选择的数据
				if (record){
					Ext.getCmp("p2form").setParam(record.data);
					var node=Ext.getCmp("rolefuncpanel").getRootNode();
					node.setId(record.data.rid);
					node.reload();
					Ext.getCmp("role_panel").layout.setActiveItem(1);//激活显示第二页
				}else{
					Ext.Msg.show({
					   title:"警告",
					   msg: "请选择要查看的信息!",
					   buttons: Ext.Msg.OK,
					   animEl: "elId",
					   icon: Ext.MessageBox.WARNING
					});
				}
			}}]
		};
		//--------------------------------------------------------------------
		var p2 = {
			id:"p2form",
			title:"角色信息",
		    labelWidth: 60,
			xtype: "form",	
			border : false,
			region: "north",
			height:180,		
		    bodyStyle:"padding:5px 5px 0",
			defaultType: "textfield",
			items: [{
				itemId: "rid",
				disabled:true,
				fieldLabel: "角色编号",
				anchor:"100%",
				name: "rid"
			},{
				itemId: "rname",
				fieldLabel: "角色名称",
				anchor:"100%",
				name: "rname",
				disabled:true,
				vtype:"alphanumchinese",
				validator:function (val){
	        		if(val=="")return "该输入项为必输项！";
	        		if(Ext.fucCheckCHLength(val)>50){
	        			return "请输入50个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			},{
				itemId: "dname",
				fieldLabel: "部门名称",
				anchor:"100%",
				disabled:true,				
				name:"dname"
			}, {
				itemId: "oname",
				disabled:true,
				fieldLabel: "机构名称",
				anchor:"100%",
				name: "oname"
			}, {
				itemId: "remark",
				fieldLabel: "备注",
				anchor:"100%",
				name: "remark",
				disabled:true,
				vtype:"alphanumchinese",
				validator:function (val){
	        		if(val=="")return true;
	        		if(Ext.fucCheckCHLength(val)>200){
	        			return "请输入200个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			}],
			showData:null,
			setParam: function(data){
				var me = this;
				me.showData=data;
				me.getComponent("rid").setValue(data.rid);//角色ID
				me.getComponent("rname").setValue(data.rname);//角色名称
				me.getComponent("dname").setValue(data.dname);//部门名称
				me.getComponent("oname").setValue(data.oname);//机构名称
				me.getComponent("remark").setValue(data.remark);//备注
				}
		};
		//--------------------------------------------------------------------
		var p3=new Ext.Panel({
			id:"rule_p3",
			layout: "border",
			items: [p2,{
			    xtype:"billTreePanel",
			    region: "center",
			    id:"rolefuncpanel",
				width : "100%",
				title:"角色权限设置",
				rootVisible:false,
				dataUrl:"treeCheck!rolefunc.action",
				root:{
					id:"root"
				}
			}],
			buttonAlign:"center",
			buttons:[
				{
				text:"返回", handler: function(){
					Ext.getCmp("role_panel").layout.setActiveItem(0);//显示第二界面
				}
				}
			]
			
		});
		
		var role_pel = new Ext.Panel({
			id:"xxxpanel",
			border : false,
			layout: "border",
			items: [{
					id:"roleTree",
					xtype: "billTreePanel",
					dataUrl: "tree!role.action",
					root: new Ext.tree.AsyncTreeNode({
						id:"root",//跟节点ID
						expanded : true//是否展开
					}),
					listeners: {
						"click": function(node){
							store.baseParams={};
							if(node.isLeaf()){
								store.baseParams["role.did"]=node.id;
								store.load();//获取部门信息
								Ext.getCmp("role_panel").layout.setActiveItem(0);//显示第二界面
							}
						}
					}
				},{
					id: "role_panel",
					region: "center",
					layout:"card",
					border : false, 
					activeItem:0,//显示第一个容器
					items: [p1, p3]
			}]
		});
		
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(role_pel);
	CenterPanel.doLayout();
	</script>
